package com.demo.homework;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * @ClassName Test2
 * @Description TODO
 * @Author tianqinglong
 * @Date 16:26 2022/7/7
 * @Version 1.0
 **/
public class homework2 {
    public static void main(String[] args) {
        /**
         * 生日前一周的周四是该年的第几天
         */
        int sum = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入年份:");
        int year11 = sc.nextInt();
        Date d = new Date(year11, 2, 27);// 年份 y 由整数 y - 1900 表示。 月份由从 0 至 11
        int year = d.getYear();
        int month = d.getMonth();
        int day = d.getDate();
        int days[] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
        sum = days[month - 1] + day;
        if (year % 4 == 0 && year % 100 != 0 && month > 2 || year % 400 == 0 && month > 2) {
// 判断是否是闰年
            sum++;
        }
//        System.out.println("这是一年的第" + sum + "天");

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);
        int yearDay = calendar.get(Calendar.DAY_OF_YEAR);
        System.out.println("(2000/3/27)上一周周四是本年的第" + (yearDay-4)  + "天");

/**
 * 设置生日
 */
        Calendar c = Calendar.getInstance();
        c.set(2000, 2, 27);
        int year1=c.get(Calendar.YEAR);
        int month1=c.get(Calendar.MONTH)+1;
        int date = c.get(Calendar.DATE);
        System.out.println(year1+"年"+month1+"月"+date+"日");


        /**
         *  add方法   不是很会
         */

        calendar.setTime(new Date());
        int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
        int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
        int yearDay1 = calendar.get(Calendar.DAY_OF_YEAR);
        if (weekDay == 1) {
            weekDay = 7;
        } else {
            weekDay = weekDay - 1;
        }
        c.add(Calendar.YEAR, -4);
        int yearDay2 = calendar.get(Calendar.DAY_OF_YEAR);
//        System.out.println("当前时间是，本周的第" + weekDay  + "天");
//        System.out.println("当前时间是，本月的第" + monthDay + "天");
        System.out.println("本年(2022/7/7)这周的上一周周四是今年的第" + (yearDay2-7)  + "天");

    }
}
